package com.anbinh.doctor.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.anbinh.doctor.R;
import com.anbinh.doctor.model.ItemTime;

public class LichhenAdapter extends ArrayAdapter<ItemTime> {
	private int resource;
	private LayoutInflater layoutInflater;
	private List<ItemTime> listData;
	private int idCheked;

	public LichhenAdapter(Context mContext, int resource,
			List<ItemTime> models, int idChecked) {
		super(mContext, resource, models);
		this.resource = resource;
		this.listData = models;
		layoutInflater = LayoutInflater.from(mContext);
		this.idCheked = idChecked;
	}

	public class ViewHolder {
		public TextView lblStatus;
		public TextView lblTime;

	}

	@Override
	public ItemTime getItem(int position) {
		return listData.get(position);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = layoutInflater.inflate(resource, null, true);
			viewHolder.lblStatus = (TextView) convertView
					.findViewById(R.id.lblStatus);

			viewHolder.lblTime = (TextView) convertView
					.findViewById(R.id.lblTime);

			convertView.setTag(viewHolder);

		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		ItemTime item = getItem(position);

		viewHolder.lblTime.setText(item.getTime());

		if (position < 5) {
			viewHolder.lblStatus.setBackgroundResource(R.drawable.ic_checked);
		} else if (position < 10) {
			viewHolder.lblStatus.setBackgroundResource(R.drawable.ic_unchecked);
		} else if (position < 15) {
			viewHolder.lblStatus.setBackgroundResource(R.drawable.ic_dakham);
		} else {
			viewHolder.lblStatus.setBackgroundResource(R.drawable.ic_baothuc);
		}

		return convertView;
	}
}
